//TestModel
//2020-08-05 10:18:52

package models

import (
	"git.900sui.cn/kc/base/common/functions"
	"git.900sui.cn/kc/base/common/models/base"
	"git.900sui.cn/kc/kcgin/orm"
)

//表结构体
type TestModel struct {
	Model *base.Model
	Field TestModelField
}

//表字段
type TestModelField struct {
	T_table string `default:"test"`
	F_id    string `default:"id"`
	F_test  string `default:"test"`
	F_num   string `default:"num"`
}

//初始化
func (t *TestModel) Init(ormer ...orm.Ormer) *TestModel {
	functions.ReflectModel(&t.Field)
	t.Model = base.NewModel(t.Field.T_table, ormer...)
	return t
}

//新增数据
func (t *TestModel) Insert(data map[string]interface{}) int {
	result, _ := t.Model.Data(data).Insert()
	return result
}

//新增数据
func (t *TestModel) Find(id int) map[string]interface{} {
	result := t.Model.Where(map[string]interface{}{
		t.Field.F_test: id,
	}).Find()
	return result
}

//新增数据
func (t *TestModel) Update(id int) (int, error) {
	return t.Model.Where(map[string]interface{}{
		t.Field.F_test: id,
	}).Data(map[string]interface{}{
		t.Field.F_num: []interface{}{"inc", 1},
	}).Update()
}
